package com.sofwin.yyb.service.impl;

import com.sofwin.yyb.dao.UserDao;
import com.sofwin.yyb.entity.User;
import com.sofwin.yyb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    public void addUser(User user) {
        userDao.insert(user);
    }

    @Override
    public boolean deleteById(Integer id) {
        int num = userDao.deleteById(id);
        System.out.println(num);
        if(num != 0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public void updateByNickname(Map<String, Object> map) {
        userDao.updateByNickname(map);
    }

    @Override
    public void updateByPassword(Map<String, Object> map) {
        userDao.updateByPassword(map);
    }

    @Override
    public void updateByPhone(Map<String, Object> map) {
        userDao.updateByPhone(map);
    }

    @Override
    public void updateByAvatar(Map<String, Object> map) {
        userDao.updateByAvatar(map);
    }

    @Override
    public User findByUser(User user) {
        User u = userDao.selectByUser(user);
        return u;
    }

    @Override
    public User findById(Integer id) {
        return userDao.selectById(id);
    }

    @Override
    public List<User> findAllUserByPage(Map<String,Object> map) {
        List<User> userList = userDao.selectAllUserByPage(map);
        return userList;
    }

    @Override
    public Integer userCount(String search) {
        return userDao.selectUserCount(search);
    }

    @Override
    public List<User> findAllUser() {
        return userDao.selectAllUser();
    }
}
